package eu.connect.im;

import org.xml.sax.Attributes;

import com.echomine.common.ParseException;
import com.echomine.jabber.JabberMessage;

public class XMPPMsgSessionInit extends JabberMessage
{
	private String initMsg;
	
	public XMPPMsgSessionInit(String namespaceURI, String localName, String qName, Attributes attr)
	{
		StringBuffer buffer = new StringBuffer(200);
		buffer.append("<?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'");
		for (int i = 0; i < attr.getLength(); i++)
		{
			String attrQName = attr.getQName(i);
			String attrPrefix;
			if (attrQName.lastIndexOf(":") != -1)
				attrPrefix = attrQName.substring(0, attrQName.lastIndexOf(":"));
			else
				attrPrefix = "";
			buffer.append(" " + attrQName + "='" + attr.getValue(i) + "'");
			if (!attrPrefix.equals(""))
			{
				buffer.append(" xmlns:" + attrPrefix + "='" + attr.getURI(i) + "'");
			}
		}
		buffer.append(">");
		initMsg = buffer.toString();
	}
	
	@Override
	public String encode() throws ParseException
	{
		return this.initMsg;
	}

	@Override
	public int getMessageType()
	{
		// TODO Auto-generated method stub
		return 1;
	}

}
